<?php

namespace app\api\controller;

use app\model\OldReview;
use app\service\TestService;
use app\value\datas\TestData;
use support\BaseResponse;
use support\Request;

class IndexController
{
    public function json(Request $request)
    {
        //加载 service
        load_service(['test']);
        // 请求参数
        $data = $request->get();
        //对数据进行验证
        $validated = validate_request(requestClass:\app\api\request\GetRequest::class, input:$data);
        //调用 logic
        $msg = TestService::instance()->hello('world');
        $res = OldReview::query()->first();
        //如果有钩子的话
        hooks_action(key: 'test', params: ['params' => 'test']);

        $res = TestData::from($res->toArray())->transform();
        //返回数据
        return BaseResponse::ok(data:$res, msg:$msg);
    }

}
